package com.apes.framework.util.monitor.druid.sql;

import com.apes.framework.util.DateUtil;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

@Data
@Document(indexName = "logs-sql_stack", replicas = 0)
public class SqlStack {

    @Id
    private String id;

    private String sqlHash;

    /**
     * sql
     **/
    private String sql;

    /**
     * 消息内容
     **/
    private String stackTrace;

    /**
     * 次数
     **/
    private int times = 0;

    public void incTimes() {
        this.times += 1;
    }

    /**
     * 创建时间
     **/
    @Field(type = FieldType.Date)
    private String createdOn = DateUtil.format("yyyy-MM-dd'T'HH:mm:ss.SSS") + "+0800";

    /**
     * 更新时间
     **/
    @Field(type = FieldType.Date)
    private String endedOn = DateUtil.format("yyyy-MM-dd'T'HH:mm:ss.SSS") + "+0800";
}
